/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package muhnes.sizoo.controlador;

import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import muhnes.sizoo.dal.RecolectorDao;
import muhnes.sizoo.dal.RecolectorDaoImpl;
import muhnes.sizoo.modelo.Recolector;
/**
 *
 * @author Ricardo Orellana
 */
@ManagedBean(name = "recolectorBean")
@ViewScoped
public class RecolectorBean extends CRUDBean implements Serializable {

    private Recolector recolector;
    private List<Recolector> listaRecolectores;
    
    public RecolectorBean() {
        super();
        RecolectorDao dao = new RecolectorDaoImpl();
        recolector = new Recolector();
        listaRecolectores = dao.buscarTodos();
    }

    public Recolector getRecolector() {
        return recolector;
    }

    public void setRecolector(Recolector recolector) {
        this.recolector = recolector;
    }
    
    public List<Recolector> getListaRecolectores() {
        if( listaRecolectores == null ) {
            RecolectorDao dao = new RecolectorDaoImpl();
            listaRecolectores = dao.buscarTodos();
        }
        return listaRecolectores;
    }

   public void prepararAdicion( ActionEvent event  ){
        recolector = new Recolector();
    }
    
    public void prepararModificacion( Recolector recolector ){
        this.recolector = recolector;
    }
    
    public void prepararEliminacion( Recolector recolector ){
        this.recolector = recolector;
    }
    
    public void agregarRecolector( ActionEvent event ){
        RecolectorDaoImpl dao = new RecolectorDaoImpl();
        recolector.setHabilitado( Boolean.TRUE );
        dao.guardar( recolector );
        recrearLista();
    }
    
     public void actualizarRecolector( ActionEvent event ){
        RecolectorDaoImpl dao = new RecolectorDaoImpl();
        dao.actualizar( recolector );
        recrearLista();
    }
    
    public void eliminarRecolector( ActionEvent event ){
        RecolectorDaoImpl dao = new RecolectorDaoImpl();
        dao.eliminar( recolector );
        recrearLista();
    }
    
    void recrearLista() {
        listaRecolectores = null;
    }
}
